/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-05-16
 * Time: 23:03
 */
public class RemoveDuplicates {
    public static int removeDuplicates(int[] nums) {
        if (nums.length==0){
            return 0;
        }
        int tmp=0;
        int cur=1;
        while (cur< nums.length){
            if (nums[tmp]!=nums[cur]){
                tmp++;
                nums[tmp]=nums[cur];
                cur++;
            }else {
                cur++;
            }
        }
        return tmp+1;
    }
    public static void main(String[] args) {
        int[] nums =new int[]{1,1,2}; // 输入数组

        int k = removeDuplicates(nums); // 调用

        for (int i = 0; i < k; i++) {
            System.out.println(nums[i]+" ");;
        }
    }
}
